<template>
  <a-card :bordered="false" class="card-area">
    <div class="table-page-search-wrapper">
      <a-form :form="form" layout="inline">
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="当前学年"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-select v-decorator="['schoolYear',
                {
                  rules: [{ required: true, message: '请选择当前学年!' }]
                }]">
                <a-select-option v-for="i in TYPE0125" :key="i.id" :value="String(i.code)">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            学校当前所在的学年，例如2012-2013
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="当前年级"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-select v-decorator="['currentGrade',
                {
                  rules: [{ required: true, message: '请选择当前年级!' }]
                }]">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="String(i.code)">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            学校当前所在的年级，例如2016
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="当前学期"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-select v-decorator="['currentSemester',
                {
                  rules: [{ required: true, message: '请选择当前学期!' }]
                }]">
                <a-select-option v-for="i in TYPE0072" :key="i.id" :value="String(i.code)">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            学校当前所在的学期
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="春季第一周开始时间"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-date-picker v-decorator="['cjkxsj',
                {
                  rules: [{ required: true, message: '请选择春季第一周开始时间!' }]
              }]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="春季最后一周结束时间"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-date-picker v-decorator="['cjjssj',
                {
                  rules: [{ required: true, message: '请选择春季最后一周结束时间!' }]
              }]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="秋季第一周开始时间"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-date-picker v-decorator="['qjkssj',
                {
                  rules: [{ required: true, message: '请选择秋季第一周开始时间!' }]
              }]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="秋季最后一周结束时间"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-date-picker v-decorator="['qjjssj',
                {
                  rules: [{ required: true, message: '请选择春季最后一周结束时间!' }]
              }]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="中期考核硕士生优秀人数百分比上限"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-input v-decorator="['postgraduateGoodNumber',
                {
                  rules: [{ required: true, message: '请填写中期考核硕士生优秀人数百分比上限!' }]
                }]"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            中期考核硕士生优秀人数百分比上限
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="中期考核博士生优秀人数百分比上限"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-input v-decorator="['doctorGoodNumber',
                {
                  rules: [{ required: true, message: '请填写中期考核博士生优秀人数百分比上限!' }]
                }]"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            中期考核博士生优秀人数百分比上限
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="考试不及格处理"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-select v-decorator="['failDispose',
                {
                  rules: [{ required: true, message: '请选择考试不及格处理!' }]
                }]">
                <a-select-option v-for="i in TYPE0356" :key="i.id" :value="String(i.code)">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            学生考试分数不及格时补考还是重修
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="研究生院单位编号"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-input v-decorator="['unitCode',
                {
                  rules: [{ required: true, message: '请填写研究生院单位编号!' }]
                }]"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            设置当前学校研究生院的单位编号
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="成绩及格分数线（分数线）"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-input v-decorator="['passLineScore',
                {
                  rules: [{ required: true, message: '请填写成绩及格分数线（分数线）!' }]
                }]"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            分数类成绩的及格分数线，输入值为整数
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="成绩及格分数线（等级线）"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-select v-decorator="['passLineGrade',
                {
                  rules: [{ required: true, message: '请选择成绩及格分数线（等级线）!' }]
                }]">
                <a-select-option v-for="i in TYPE0357" :key="i.id" :value="String(i.code)">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            等级类成绩的及格分数线
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="学校管理模式"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-select v-decorator="['managementMode',
                {
                  rules: [{ required: true, message: '请选择学校管理模式!' }]
                }]">
                <a-select-option v-for="i in TYPE0355" :key="i.id" :value="String(i.code)">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            一级模式主要由研究生院培养办或研究生处进行研究生平台的事务管理；
            二级模式可以由研究生院培养办和院系共同参与在研究生平台中分工处理相关事务。
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="导师批准年月"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-select v-decorator="['tutorRatifyMonth',
                {
                  rules: [{ required: true, message: '请选择导师批准年月!' }]
                }]">
                <a-select-option v-for="i in TYPE0383" :key="i.id" :value="String(i.code)">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            导师录用批准年月
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="博士招生学年"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-select v-decorator="['doctoralAdmissionYear',
                {
                  rules: [{ required: true, message: '请选择博士招生学年!' }]
                }]">
                <a-select-option v-for="i in TYPE0387" :key="i.id" :value="String(i.code)">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            博士招生学年
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="学位课成绩及格分数线"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-input v-decorator="['degreeCoursePassLine',
                {
                  rules: [{ required: true, message: '请填写学位课成绩及格分数线!' }]
                }]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="硕士招生学年"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-select v-decorator="['masterAdmissionYear',
                {
                  rules: [{ required: true, message: '请选择硕士招生学年!' }]
                }]">
                <a-select-option v-for="i in TYPE0387" :key="i.id" :value="String(i.code)">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            硕士招生学年
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="非学位课成绩及及格分数线"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-input v-decorator="['unDegreeCoursePassLine',
                {
                  rules: [{ required: true, message: '请填写非学位课成绩及及格分数线!' }]
                }]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="导师硕士招生年龄线"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-date-picker v-decorator="['tutorMasterAdmissionAgeLine',
                {
                  rules: [{ required: true, message: '请选择导师硕士招生年龄线!' }]
              }]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="导师博士招生年龄线"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-date-picker v-decorator="['tutorDoctoralAdmissionAgeLine',
                {
                  rules: [{ required: true, message: '请选择导师博士招生年龄线!' }]
                }]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="导师专硕专业个数"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-input v-decorator="['tutorTotalEnrollment',
                {
                  rules: [{ required: true, message: '请填写导师专硕专业个数!' }]
                }]"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            本年度专硕专业个数限制
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="导师学硕专业个数"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-input v-decorator="['tutorTotalMasterEnrollmentNumber',
                {
                  rules: [{ required: true, message: '请填写导师学硕专业个数!' }]
                }]"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            本年度硕导专业专业个数限制
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="12" :sm="24">
            <a-form-item
              label="导师博士专业个数"
              :labelCol="{span: 7,offset: 1}"
              :wrapperCol="{span: 15, offset: 1}"
            >
              <a-input v-decorator="['tutorTotalDoctoralEnrollmentNumber',
                {
                  rules: [{ required: true, message: '请填写导师博士专业个数!' }]
                }]"/>
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="24">
            本年度博导专业专业个数限制
          </a-col>
        </a-row>
        <a-input v-decorator="['id']" hidden/>
      </a-form>
      <a-row style="text-align:center;margin:30px;">
        <a-button :loading="loading" type="primary" @click="saveForm">确定</a-button>
      </a-row>
    </div>
  </a-card>
</template>

<script>
import { mapState } from 'vuex'
import moment from 'moment'

export default {
  data () {
    return {
      id: '',
      loading: false
    }
  },
  beforeCreate () {
    this.form = this.$form.createForm(this)
  },
  computed: {
    ...mapState({
      TYPE0126: state => state.app['TYPE0126'], // 年级
      TYPE0072: state => state.app['TYPE0072'], // 学期
      TYPE0387: state => state.app['TYPE0387'], // 博士（硕士）招生学年
      TYPE0356: state => state.app['TYPE0356'], // 考试不及格处理
      TYPE0355: state => state.app['TYPE0355'], // 管理模式
      TYPE0357: state => state.app['TYPE0357'], // 等级类成绩的及格分数线
      TYPE0125: state => state.app['TYPE0125'], // 学校当前所在的学年
      TYPE0383: state => state.app['TYPE0383'] // 导师批准年月
    })
  },
  created () {
    this.$api.system.info().then(res => {
      this.$changeDate(res.data)
      this.id = res.data.id
      this.$nextTick(() => {
        this.form.setFieldsValue(res.data)
      })
    })
    this.$store.dispatch('app/setDictionary', 'TYPE0126')
    this.$store.dispatch('app/setDictionary', 'TYPE0072')
    this.$store.dispatch('app/setDictionary', 'TYPE0387')
    this.$store.dispatch('app/setDictionary', 'TYPE0356')
    this.$store.dispatch('app/setDictionary', 'TYPE0355')
    this.$store.dispatch('app/setDictionary', 'TYPE0357')
    this.$store.dispatch('app/setDictionary', 'TYPE0125')
    this.$store.dispatch('app/setDictionary', 'TYPE0383')
  },
  methods: {
    saveForm () {
      this.form.validateFields((err, values) => {
        if (err) {
          return
        }
        this.loading = true
        this.$DateToString(values)
        for (let key in values) {
          if (values[key] instanceof moment) {
            values[key] = moment(values[key]).format('YYYY-MM-DD')
          }
        }
        this.$api.system.update(Object.assign({id: this.id}, values)).then(res => {
          this.$message.success(res.msg)
          this.$store.dispatch('app/sysInfo', true)
        }).finally(() => {
          this.loading = false
        })
      })
    }
  }
}
</script>

<style>

</style>
